課題1 課題2 課題3 課題4 課題5 課題6 参考文献

課題1:telnetコマンドによるWWWサーバへのアクセス

telnetコマンドを使って任意のWWWサーバにアクセスし、任意のURLのページデ ータ(htmlソースプログラム)を画面に表示せよ。


実行結果
[nw0546:~] j05046% telnet www.toranoana.jp 80
Trying 202.213.240.16...
Connected to www.toranoana.jp.
Escape character is '^]'.
GET /index.html HTTP/1.0

<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta name="Author" content="toranoana">
<link rev="made" href="mailto:admin@toranoana.co.jp">
<link rel="stylesheet" href="http://www.toranoana.jp/css/toppage.css" type="text/css">
 Web Site</title>
</head>
<style type="text/css">
<!--
body {
                padding-right: 0px;
                padding-left: 0px;
                padding-bottom: 0px;
                padding-top: 0px;
}
-->
</style>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" bgcolor="#EEEEEE" text="#FFFFFF">
<table border="0" width="580" height="100%" cellpadding="0" cellspacing="0">
<tr><td bgcolor="#FF9900;" colspan="2" height="70">
<div style="float: right; width: 120px; padding: 0 4 0 0; text-align: right;">
<a style="font-size: 8pt; color: #FF9900;" href="http://tiger.tora-mobile.jp/eo/volt/index.html">mobile</a><br>
<img src="http://www.toranoana.jp/image/toralogo3.gif">
</div>
@<img src="image/title.gif">
</td></tr>
<tr><td bgcolor="#FFFFFF" valign="top" width="120">
<table cellpadding="0" cellspacing="0">
<tr height="21"><td>&nbsp;
</td></tr><tr><td height="32">

課題2:inetdを使用するサーバプログラムの作成

サンプルプログラム(1)はサーバ(server.c)をinetdから起動することで、サーバはクライアント(client.c)の標準入力から入力された文字に対応するキーワードをクライアントに返すプログラムである。サンプルプログラム(1)を自分の実験環境で動作するようにし、実行結果を示すとともに、プログラムの中で使われている関数(Connect,Disconnect, Send Data, Recv Dataなど)の動作を説明し、サーバ・クライアント動作全体をフローを示して説明せよ。

サンプルプログラムをダウンロードして「/Users/j05046/jikken2/」に入れる

"server.c"と"client.c"に#includeを追加する

サンプルプログラムの"server.c"のDATAFILEの所のdataを/Users/j05046/jikken2/data.txtにかえる。

"cliant.c"のHOST_NAMEの所をnw0546にした。

"etc/inetd.conf"を編集する

アクセス権を変更して、inetd.confに書き込めるようにする。

"tcpinetd stream tcp nowait root /Users/j05046/jikken2/server"を一番下に追加

"# /sbin/service --list"の「#」を削除する.

"etc/services"を編集する

アクセス権を変更して、servicesに書き込めるようにする。

一番下にtcpinetd 5682/tcpを追加

"server.c"と"client.c"をコンパイルする。

cc -g -o server server.c

cc -g -o client client.c

"sudo xinetd -inetd_compat"としてxinetdを動かして、"./cliant"で実行する。



[nw0546:~/jikken2] j05046% ./client
Connected.
Input Keyword = warning: this program uses gets(), which is unsafe.
yama
Keyword = [yama] / Data = [kawa]

Input Keyword = 123
Keyword = [123] / Data = [456]

Input Keyword = siro
Keyword = [siro] / Data = []

Input Keyword = shiro
Keyword = [shiro] / Data = [kuro]

Input Keyword = xxxx
Keyword = [xxxx] / Data = [yyyy]

Input Keyword = ^C^X


関数の動作説明

課題3:inetdを使用しないサーバプログラムの作成

ソース

server.cのソース

実行結果

[nw0546:~/jikken2/tcp] j05046% server & [1] 208 [nw0546:~/jikken2] j05046% ./client Connected. Input Keyword = warning: this program uses gets(), which is unsafe. yama Keyword = [yama] / Data = [kawa] Input Keyword = shiro Keyword = [shiro] / Data = [kuro] Input Keyword = 123 Keyword = [123] / Data = [456] Input Keyword = xxxx Keyword = [xxxx] / Data = [yyyy] Input Keyword = Disocnnected.

考察

inetdの起動した場合,クライアントが要求を送るたびにサーバが立ち上がったり、終了したりするので頻繁なアクセスがある。よって、サーバの実行や終了に時間がかかる。

課題4:HTTPクライアントの作成

ソケットおよびHTMLを使ってWWWサーバから任意のURLのページを取得し、標準出力に出力するプログラムを作成せよ。

ソース

get4.0.cのソース

実行結果

[nw0546:~/jikken2/tcp4] j05046% cc -g -o get get4.0.c [nw0546:~/jikken2/tcp4] j05046% ./get http://www.ie.u-ryukyu.ac.jp/~j05058 http://www.ie.u-ryukyu.ac.jp/~j05058 を取得します。 GET /~j05058 HTTP/1.0 Host: www.ie.u-ryukyu.ac.jp:80 HTTP/1.1 301 Moved Permanently Date: Fri, 15 Dec 2006 05:25:16 GMT Server: Apache/2.0.55 (Unix) mod_ssl/2.0.55 OpenSSL/0.9.7i PHP/5.1.2 Location: http://www.ie.u-ryukyu.ac.jp/~j05058/ Cache-Control: max-age=60 Expires: Fri, 15 Dec 2006 05:26:16 GMT Content-Length: 370 Connection: close Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://www.ie.u-ryukyu.ac.jp/~j05058/">here</a>.</p> <hr> <address>Apache/2.0.55 (Unix) mod_ssl/2.0.55 OpenSSL/0.9.7i PHP/5.1.2 Server at www.ie.u-ryukyu.ac.jp Port 80</address> </body></html>

課題5:ポートスキャンの実験

自分の実験環境(端末)の使用/未使用ポート(ウェルノウンポートのみでok)を確認するポートスキャンプログラムを作成せよ。さらに、任意のリモート端末の使用/未使用ポートを確認するように改良せよ(加点ポイント)。なお、スクリプトを使って内部で'netstat -l'コマンドを実行し、その結果を利用するのは不可とする(ソケットプログラムを作成すること)。

ソース

port.cのソース

実行結果

[nw0546:~/jikken2/tcp4] j05046% cc -g -o port port.c [nw0546:~/jikken2/tcp4] j05046% port Address = "133.13.59.46" Portscan started.. Open TCP Port: 80 Open TCP Port: 427 Open TCP Port: 548 Portscan find them.

課題6:バッファオーバーフローの実験

サンプルプログラム(2)を実行せよ。このプログラムはgets()関数を用いて、標準入力からの入力をバッファにデータを読み込むものであるが、結果を見ると、プログラム中で操作していないバッファdmy[]に値が入ることがある。この原因を考察し、解決策を示せ。また、この問題によって引き起こされるTCP/IP通信におけるセキュリティ上の欠陥はどのようなものが考えられるか、具体例を挙げて述べよ。

修正後のソース

buf.cのソース

修正前の実行結果

[nw0546:~/jikken2/tcp4] j05046% cc -g -o bufovf bufovf.c [nw0546:~/jikken2/tcp4] j05046% bufovf before buf(Len:0) = dmy(Len:0) = warning: this program uses gets(), which is unsafe. 111111111112333333334553223421312312 after buf(Len:36) = 111111111112333333334553223421312312 dmy(Len:0) =

修正後の実行結果

"gets()"ではなく"fgets()"を使った。
[nw0546:~/jikken2/tcp4] j05046% cc -g -o bufovf bufovf.c [nw0546:~/jikken2/tcp4] j05046% bufovf before buf(Len:0) = dmy(Len:0) = 123456789123456 after buf(Len:11) = 12345678912 dmy(Len:0) =

セキュリティ上の欠陥

ごくわずかな不正プログラミング・コードが意図的に送りつけられた大量の情報によってあふれることで発生し、標的となったシステムは悪意をもった攻撃者による制御が可能になります。


参考文献